<template>
  <div class="login_container">
    <div class="title_login">elm后台管理系统</div>
    <div class="login_box">
      <!-- 表单开始 -->
      <el-form
        ref="loginFormRef"
        :model="loginForm"
        :rules="loginFormRules"
        label-width="0"
        class="login_form"
      >
        <!-- 用户名开始 -->
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" placeholder="请输入用户名" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <!-- 用户名结束 -->
        <!-- 密码开始 -->
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            type="password"
            placeholder="请输入密码"
            prefix-icon="el-icon-lock"
          ></el-input>
        </el-form-item>
        <!-- 密码结束 -->
        <!-- 登录按钮开始 -->
        <el-form-item class="Btns">
          <el-button type="primary" @click="loginBtn">登录</el-button>
          <el-button type="info" @click="resetLoginForm">重置</el-button>
        </el-form-item>
        <!-- 登录按钮结束 -->
      </el-form>
      <!-- 表单结束 -->
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 登录表单数据绑定对象
      loginForm: {
        username: "admin",
        password: "123456",
      },
      // 表单验证规则对象
      loginFormRules: {
        // 验证用户名是否合法
        username: [
          { required: "ture", message: "请输入用户名", trigger: "blur" },
          {
            min: 2,
            max: 10,
            message: "长度在 2 到 10 个字符",
            trigger: "blur",
          },
        ],
        // 验证密码是否合法
        password: [
          { required: "ture", message: "请输入用户密码", trigger: "blur" },
          {
            min: 6,
            max: 12,
            message: "长度在 6 到 12 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    //
    loginBtn() {
      if (!this.loginForm.username.trim()) {
        alert("用户名不能为空");
        return;
      } else if (!this.loginForm.password.trim()) {
        alert("密码不能为空");
        return;
      } else {
        alert("登录成功");
        this.$router.push({ path: "/index" });
      }
    },
    resetLoginForm(){
      this.$refs.loginFormRef.resetFields();
      alert("重置成功")
    }
  },
};
</script>

<style>
html,body{
  margin: 0;
  padding: 0;
}
html {
  height: 100%;
}
body {
  height: 100%;
}
#app {
  height: 100%;
}
.login_container {
  height: 100%;
  background: url(https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1598444440411&di=278a2f3e778a530c686a19b92bbe21bd&imgtype=0&src=http%3A%2F%2Fattach.bbs.miui.com%2Fforum%2F201209%2F18%2F1750038ve0hhe9vk8dhv8z.jpg)
    no-repeat;
  background-size: 100% 100%;
  overflow: hidden;
}
.title_login {
  width: 100%;
  height: 50px;
  line-height: 50px;
  text-align: center;
  font-size: 32px;
  color: #fff;
  margin-top: 325px;
}
.login_box {
  width: 350px;
  height: 168px;
  background-color: rgba(255, 255, 255, 0);
  margin: 40px auto 0;
}
.Btns {
  display: flex;
  justify-content: center;
}
.el-button--primary,
.el-button--info {
  width: 170px;
}

</style>